package com.haotunet.app.goldtreasure.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.haotunet.app.goldtreasure.R;
import com.haotunet.app.goldtreasure.model.VaultRecordInfo;

import java.util.List;

public class VaultDetailAdapter extends HolderAdapter<VaultRecordInfo, VaultDetailAdapter.ViewHolder> {

	public VaultDetailAdapter(Context context, List<VaultRecordInfo> mlist) {
		super(context, mlist);
	}

	public static class ViewHolder {
		TextView mOperation;
		TextView mDate;
		TextView mQuantity;
	}

	@Override
	public View buildConvertView(LayoutInflater layoutInflater, VaultRecordInfo t, int position) {
		return inflate(R.layout.item_vault_detail);
	}

	@Override
	public ViewHolder buildHolder(View convertView, VaultRecordInfo t, int position) {
		ViewHolder holder = new ViewHolder();
		holder.mDate = (TextView) convertView.findViewById(R.id.txt_date);
		holder.mOperation = (TextView) convertView.findViewById(R.id.txt_operation);
		holder.mQuantity = (TextView) convertView.findViewById(R.id.txt_quantity);
		return holder;
	}

	@Override
	public void bindViewDatas(View convertView, ViewHolder holder, VaultRecordInfo vaultRecordInfo, int position) {
		holder.mDate.setText(vaultRecordInfo.getTransactionTime());
		holder.mOperation.setText(vaultRecordInfo.getOperation());
		String goldWeight = vaultRecordInfo.getGoldWeight().trim();
		if ("+".equals(goldWeight.substring(0, 1))) {
			holder.mQuantity.setTextColor(context.getResources().getColor(R.color.color_red));
		} else if ("-".equals(goldWeight.substring(0, 1))) {
			holder.mQuantity.setTextColor(context.getResources().getColor(R.color.color_green));
		} else {
			holder.mQuantity.setTextColor(context.getResources().getColor(R.color.color_black));
		}
		holder.mQuantity.setText(goldWeight);
	}
}
